#!/bin/bash -f
awk '{ps=0;pe=0;for(i=1;i<NF;i+=1){if($(i)~/\[\w+/){ps=i;break}} for(i=ps+1;i<NF;i+=1) {if($(i)~/\w+\]/){pe=i;break}}; if(pe<=ps){if($(i)~/\[\w+\]/){ps=i;pe=i}}; for(i=ps;i<=pe;i+=1) {printf("%s",$(i))}; printf(" %s %s\n",$1,$2)}' $1
